package com.xr.common.businessRemind;

import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.bstek.dorado.common.*;
import com.xr.common.Tools;
import com.xr.system.User;

/**
 * BusinessRemindQuery_datasetRemindListListener
 */
public class BusinessRemindQuery_datasetRemindListListener extends AbstractDatasetListener {
  public boolean beforeLoadData(Dataset dataset) throws Exception {

    String sql="select rmd.business_remind_id,rmd.remind_type,rmd.remind_memo,"
              +"rmd.employee_id,rmd.company_id,"
              +"emp.employee_code,emp.employee_name,emp.id_card_type,emp.id_card_num,"
              +"com.company_code,com.company_chinese_name,com.company_short_name,rmd.if_knowed,rmd.knowed_time "
              +"from pb_business_remind rmd,"
              +"pb_employee emp,pb_company com "
              +"where rmd.employee_id=emp.employee_id(+) "
              +"and rmd.company_id=com.company_id(+) ";
    SqlDataset ds = (SqlDataset) dataset;
    String remindType = Tools.toStr(ds.parameters().getString("remind_type"));
	if (!"".equals(remindType)) {
		sql += " and rmd.remind_type ='" + remindType + "' ";
	}
	String remindedMan = Tools.toStr(ds.parameters().getString("reminded_man"));
	if (!"".equals(remindedMan)) {
		sql += " and rmd.reminded_man ='" + remindedMan + "' ";
	}
	String ifKnowed = Tools.toStr(ds.parameters().getString("if_knowed"));
	if (!"".equals(ifKnowed)) {
		sql += " and rmd.if_knowed ='" + ifKnowed + "' ";
	}
	String knowedTime1=ds.parameters().getDate("knowed_time1")==null?"":Tools.format(ds.parameters().getDate("knowed_time1"),"yyyyMMdd"); 
	if(!"".equals(knowedTime1)){
		sql += " and to_char(rmd.knowed_time,'yyyymmdd')>='" + knowedTime1 + "'";
	}
	String knowedTime2=ds.parameters().getDate("knowed_time2")==null?"":Tools.format(ds.parameters().getDate("knowed_time2"),"yyyyMMdd"); 
	if(!"".equals(knowedTime2)){
		sql += " and to_char(rmd.knowed_time,'yyyymmdd')<='" + knowedTime2 + "'";
	}
	//System.out.println(sql);
    ds.setSql(sql);
    return true;
  }

  public void afterLoadData(Dataset dataset)
     throws Exception {

  }

}
